<template>
	<view class="home-page">
		<view class="swiper-box" v-if="bannerConfig.isHidden == 1">
			<view class="swiper-bg"></view>
			<u-swiper :list="bannerList" name="url" :effect3d="true" circular :autoplay="true" border-radius="10" :indicator="false" bg-color="" mode="none" height="318" :interval="bannerConfig.rotationTime"></u-swiper>
		</view>

		<view class="icon-box" v-if="iconList.length > 0">
			<u-grid :border="false" col="4" >
				<u-grid-item v-for="(item,index) in iconList" @click="gotoContentList1(item)" :key="item.id" class="icon-item">
					<u-icon :custom-style="{'margin-top': '-10rpx'}"  :name="item.path" :size="22" width="96rpx" height="96rpx"></u-icon>
					<text class="icon-text">{{item.text}}</text>
				</u-grid-item>
			</u-grid>
		</view>
		<u-gap height="20" bgColor="#f5f5f5" v-if="iconList.length > 0"></u-gap>
		<view class="notice-box" @tap="gotoContentList('通知公告', 9, 2)" v-if="noticeList.length > 0">
			<image src="@/static/images/notice.png" class="notice-title-image"></image>
			<view class="notice-swiper-box">
				<swiper class="swiper-box" :vertical="true" circular :interval="5000" :autoplay="true">
					<swiper-item class="swiper-item" v-for="(item, index) in noticeList" :key="item">
						<block v-for="itemChild in item" >
							<view class="notice-item" :key="itemChild">
								<view class="dot"></view>
								<view class="text">{{itemChild}}</view>
							</view>
						</block>
					</swiper-item>
				</swiper>
			</view>
			<view class="jump-box">
				<u-icon name="arrow-right" color="#888888" size="24"></u-icon>
			</view>
		</view>
		<u-gap height="20" bgColor="#f5f5f5" v-if="noticeList.length > 0"></u-gap>
		<view class="floor-box" v-for="(item,index) in contentList" :key="item.id">
			<view class="floor-title-box">
				<view class="title-box">{{item.iconName}}</view>
				<view class="jump-box" @tap="gotoContentList(item.iconName, item.iconId, item.iconType)">
					<text class="text">全部</text>
					<u-icon name="arrow-right" color="#888888" size="22"></u-icon>
				</view>
			</view>
			<view class="floor-list">
				<block v-for="child in item.partyContentList">
					<news-item :item="child" @tap="gotoDetail(child, item.iconType)" :key="child.id"></news-item>
				</block>
				<block v-for="child in item.communityContentList">
					<news-item :item="child" @tap="gotoDetail(child, item.iconType)" :key="child.id"></news-item>
				</block>
			</view>
			<u-gap height="14" bgColor="#f5f5f5" v-if="index < (contentList.length-1)"></u-gap>
		</view>
	</view>
</template>

<script>
	import {getOne} from '@/api/home'
	export default {
		data() {
			return {
				bannerConfig: {
					rotationTime: 3000,
					isHidden: 1 // 1显示 2隐藏
				},
				bannerList: [],
				iconList: [],
				noticeList: [],
				contentList: []
			};
		},
		methods: {
			gotoContentList(title, id, iconType) {
				let url = `/pages/party-sub/content-list/content-list?title=${title}&id=${id}`
				if(iconType == 2){
					url = `/pages/home-sub/news-content-list/news-content-list?title=${title}&id=${id}`
				}
				uni.navigateTo({
					url: url
				})
			},
			gotoContentList1(item) {
				let title = item.text;
				let id = item.id;
				this.gotoContentList(title, id, 2)
			},
			gotoDetail(item, iconType) {
				let url = `/pages/party-sub/content-detail/content-detail?id=${item.id}`
				if(iconType == 2){
					url = `/pages/home-sub/news-content-detail/news-content-detail?id=${item.id}`
				}
				uni.navigateTo({
					url: url
				})
			},
			init() {
				this.searchBannerList();
				this.getPartyIconList();
				this.getNoticeList();
				this.getContentList();
				setTimeout(() => {
					uni.stopPullDownRefresh();
				}, 1200)
				
			},
			// 获取轮播图
			searchBannerList() {
				// getOne().then(res => {
				// 	let data = res.data;
				// 	this.bannerList = [];
				// 	this.bannerConfig = {
				// 		rotationTime: data.rotationTime * 1000,
				// 		isHidden: data.isHidden // 1显示 2隐藏
				// 	}

				// 	for (let i = 1; i <= 6; i++) {
				// 		if (data['pic' + i]) {
				// 			this.bannerList.push({
				// 				url: data['pic' + i]
				// 			})
				// 		}
				// 	}

				// }).catch(err => {

				// })
				// uni.$u.http.post('app/index-banner/getOne').then(res => {
				// 	let data = res.data;
				// 	this.bannerList = [];
				// 	this.bannerConfig = {
				// 		rotationTime: data.rotationTime * 1000,
				// 		isHidden: data.isHidden // 1显示 2隐藏
				// 	}

				// 	for (let i = 1; i <= 6; i++) {
				// 		if (data['pic' + i]) {
				// 			this.bannerList.push({
				// 				url: data['pic' + i]
				// 			})
				// 		}
				// 	}

				// }).catch(err => {

				// })
			},
			// 获取标签导航
			getPartyIconList() {
				uni.$u.http.post('app/community-icon/list').then(res => {
					let data = res.list;
					this.iconList = []
					data.forEach(item => {
						this.iconList.push({
							path: item.iconPic,
							text: item.iconName,
							id: item.id
						})
					})

				}).catch(err => {

				})
			},
			// 获取通知公告
			getNoticeList() {
				uni.$u.http.post('app/community-content/searchNoticeList').then(res => {
					let data = res.list;
					this.noticeList = [];
					let tempArr = [];
					for (let i = 0; i < data.length; i++) {
						tempArr.push(data[i].contentTitle)
						if (i % 2 == 1 && tempArr.length > 0) {
							this.noticeList.push(tempArr)
							tempArr = [];
						}
						if (i == data.length - 1 && tempArr.length > 0) {
							this.noticeList.push(tempArr)
							tempArr = [];
						}
					}


				}).catch(err => {

				})
			},
			// 查询党建内容
			getContentList() {
				uni.$u.http.post('app/index-icon-flow/getIconFlowContent').then(res => {
					let data = res.list;
					this.contentList = data;

				}).catch(err => {

				})
			}
		},
		onLoad() {
			this.init();
		},
		onPullDownRefresh(){
			this.init();
		}
	}
</script>

<style lang="scss">
	
</style>
